﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Daphne.GameShared;


namespace GameEngine.MoveGenerators
{
    public class JumpBackManMoveGenerator: ClassicManMoveGenerator
    {
        /// <summary>
        /// Returns jumps back for man moving up
        /// </summary>
        protected override List<Position> GetManJumpsUp(Position figurePos)
        {
            List<Position> list = base.GetManJumpsUp(figurePos);

            Position jumpedFigurePos;
            Position testPos;
            enumFigureColor clrMovedFigure = GameBoard.GetField(figurePos).FigureColor();

            jumpedFigurePos = figurePos.SouthEast;
            testPos = jumpedFigurePos.SouthEast;
            if (IsJumpValid(testPos, jumpedFigurePos, clrMovedFigure))
                list.Add(testPos);

            jumpedFigurePos = figurePos.SouthWest;
            testPos = jumpedFigurePos.SouthWest;
            if (IsJumpValid(testPos, jumpedFigurePos, clrMovedFigure))
                list.Add(testPos);

            return list;
        }

        /// <summary>
        /// For international checkers we have to check, whether the move from promotion row
        /// does not continue with jump, if yes, we cannot convert to king
        /// CHANGES FOR RUSSIAN CHECKERS
        /// </summary>
        protected override bool DoesMoveContinueWithJump(Position figurePos, enumManOrientation eOrientation)
        {
            return base.GetManJumps(figurePos, eOrientation).Count > 0;
        }

        /// <summary>
        ///  Returns jumps back for man moving down
        /// </summary>
        protected override List<Position> GetManJumpsDown(Position figurePos)
        {
            List<Position> list = base.GetManJumpsDown(figurePos);

            Position jumpedFigurePos;
            Position testPos;
            enumFigureColor clrMovedFigure = GameBoard.GetField(figurePos).FigureColor();

            jumpedFigurePos = figurePos.NorthEast;
            testPos = jumpedFigurePos.NorthEast;
            if (IsJumpValid(testPos, jumpedFigurePos, clrMovedFigure))
                list.Add(testPos);

            jumpedFigurePos = figurePos.NorthWest;
            testPos = jumpedFigurePos.NorthWest;
            if (IsJumpValid(testPos, jumpedFigurePos, clrMovedFigure))
                list.Add(testPos);

            return list;
        }
    }
}
